home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 1998 August / IRIX 6.5.1 1 of 2 Installation Tools and Overlays August 1998.img / dist / inst.init < prev    next >
Text File  |  1998-08-03  |  9KB  |  257 lines

  1. #!/bin/sh
  2. # This script will be run by inst (or swmgr) when the distribution directory,
  3. # if placed at the top level distribution directory, with the name
  4. # "inst.init".  The user is asked if the script should be run, unless
  5. # the resource "startup_script" is set to either "ignore" or "execute",
  6. # to suppress asking the question.  Automatic installs (inst -a) fail
  7. # if this resource is not set, and this file is present.
  8. # The script has access to the normal environment variables (those that
  9. # can be used by pre-, post-, and exit-ops), such as $mr, $rbase, and
  10. # $dist.
  11. # It is invoked with 3 arguments.  The first is either "inst" or "swmgr"
  12. # for scripts that want to behave differently.  The second is the distribution
  13. # path, and the third is the file descriptor number for communicating
  14. # results/commands back to inst or swmgr.
  15. #
  16. # The script should exit with the value 0 if there are no errors
  17. # if the exit value is non-zero, a warning message is printed.
  18. #
  19. # The normal output of this script and the programs it uses are not paged
  20. # in anyway, nor is the input.  Error output (stderr, descriptor 2) is
  21. # paged.  If programs are used that use stderr, but you do not want paging
  22. # (such as rm -ri), then run them with stderr directed to normal output
  23. # (rm -ri 2>&1)
  24.  
  25. distpath="$2"
  26. if [ -z "$rbase" ]; then rbase=/; fi
  27.  
  28. case "$1" { # decided whether we need a window to run in
  29. winterm) # re-invoked from swmgr; see below
  30.     stty intr '^c' # for consistency with most usage.
  31.     endmsg='\nDistribution script completed, close this window to continue'
  32.     instfd=">$3" # for selfile creation
  33.     ;;
  34. swmgr)
  35.     # can't pass a file descriptor, so use a temporary file.
  36.     # still want to use -hold, even with the "read" confirmation
  37.     # at the end, in case there are errors.
  38.     xwsh -xrm '' -xrm 'XWsh*autoFork:false' \
  39.         -title "Software Manager - Installation Startup" -hold -e $0 winterm "$2" /tmp/$$
  40.     if [ -s /tmp/$$ ]; then cat /tmp/$$ 1>&"$3"; fi
  41.     rm -f /tmp/$$
  42.     exit 0 ;; # can not get useful exit value for this case
  43. inst|*) # if missing, or wrong, treat as inst
  44.     endmsg='\nDistribution script completed, press ENTER to continue \c'
  45.     instfd=">&$3" # for selfile creation
  46.     ;;
  47. }
  48.  
  49. # sub functions defined here; invocation at end of file {
  50.  
  51. # a *really* silly way to do paging, but with no pager in the miniroot...
  52. mypager()
  53. {
  54.       2>&1 nawk -v tl=$ttylines -F ';' \
  55.         '{ print $0; l++; \
  56.           if(!(l%tl)) { \
  57.           printf "[  Press Enter for next screen, Control-C to stop ]  "; \
  58.           getline junk < "/dev/tty" } }' $1
  59. }
  60.  
  61. rminteractive()
  62. {
  63.     echo '\nThe list of files will be shown one screen at a time,'
  64.     echo 'in the format "owner   size   date  filename".'
  65.     echo 'For each screen, you will be prompted for each file in that screen.'
  66.     echo 'Preparing list ... \c'
  67.  
  68.     # the check for "uid # modify" is in case the login name can't be matched
  69.     # which is fairly likely for miniroot; in that case the name field will
  70.     # be printed as "uid=#".
  71.     (xargs stat -ums 2>/dev/null) < $1 \
  72.         | sed -e 's/ <[0-9>]*$//' -e 's,//,/,g' \
  73.           -e 's/uid \([0-9][0-9]*\)[     ]*modify/uid \1 (uid=\1) modify/' \
  74.           -e 's/modify time - ... //' \
  75.           -e 's/ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] \(....\)$/ \1/' \
  76.           -e 's/^\([^:]*\):.*; size \([0-9][0-9]*\)[^(]*(\([^)]*\)[)     ]*\(.*\)/\3;\2;\4;\1/'\
  77.         > /tmp/rmi$$;
  78.  
  79.     if [ -s /tmp/rmi$$ ]
  80.     then # 2>&1 because the rm command prompts to stderr, we want to avoid
  81.       # the inst paging of stderr
  82.       echo ''
  83.       2>&1 nawk -v tl=$rmlines -F ';' \
  84.         '{ printf "%9s %9d %s  %s\n", $1, $2, $3, $4; f=f" "$4; l++; \
  85.           if(!(l%tl)) { printf "Use Control-C to end cleanup\n"; \
  86.           system("rm -ri" f ); f="" } } \
  87.           END { if(length(f)) { printf "Use Control-C to end cleanup\n"; \
  88.           system("rm -ri" f ) } }' /tmp/rmi$$
  89.     else echo No files found to remove # should not happen
  90.     fi
  91.     rm -f /tmp/rmi$$
  92. }
  93.  
  94. diskspace()
  95. {
  96.     echo '\nDo you want to check for kernel crash files, program core files, '
  97.     echo 'dumpster directories, temporary and lost+found files that might'
  98.     echo 'prevent a successful installation? (yes/no) [yes] \c'
  99.     read ans
  100.     case "$ans" {
  101.     y*|Y*|"") ;;
  102.     *) return ;;
  103.     }
  104.  
  105.     # figure out if we need to check /usr seperately from /
  106.     rootdev="`stat -qd /$rbase`"
  107.     usrdev="`stat -qd /$rbase/usr`"
  108.     if [ "$rootdev" != "$usrdev" ]
  109.     then dirs="$rbase $rbase/usr"
  110.     else dirs="$rbase"
  111.     fi
  112.     if [ -d $rbase/lost+found ]; then lostdirs="$lostdirs $rbase/lost+found"; fi
  113.     if [ -d $rbase/usr/lost+found ]; then lostdirs="$lostdirs $rbase/usr/lost+found"; fi
  114.     if [ -d $rbase/tmp ]; then lostdirs="$lostdirs $rbase/tmp"; fi
  115.     if [ -d $rbase/usr/tmp ]; then lostdirs="$lostdirs $rbase/usr/tmp"; fi
  116.     if [ -d $rbase/var/tmp ]; then lostdirs="$lostdirs $rbase/var/tmp"; fi
  117.  
  118.     echo Searching for large files that might need to be removed.
  119.     echo This may take a few minutes... \\c
  120.  
  121.     find $dirs -mount \( -name dumpster -type d -print \)  -o \( -name core -type f -print \) >/tmp/rm$$ 2>/dev/null
  122.     find $rbase/usr/adm/crash -mount \( -name 'unix*' -o -name 'vmcore*' \) -type f -print >>/tmp/rm$$ 2>/dev/null
  123.     # 2K and larger only, to eliminate long nuisance list...
  124.     find $lostdirs -type f -size +4 -print >> /tmp/rm$$ 2>/dev/null
  125.     echo '' # end the "Searching" line above
  126.     if [ -s /tmp/rm$$ ]
  127.       then rminteractive /tmp/rm$$
  128.       else echo \\nNo files found that might need to be removed to make space
  129.     fi
  130.     rm -f /tmp/rm$$ /tmp/rm2.$$
  131. }
  132.  
  133. oldkernel()
  134. {
  135.     if [ ! -d $rbase/var/sysgen ! -d $rbase/usr/cpu/sysgen ]
  136.     then    echo '\nNo old kernel files (used to build /unix) found.'
  137.         return
  138.     fi
  139.  
  140.         REL=`uname -r`
  141.     echo '\nIf you are doing a full installation from an IRIX release *prior*'
  142.     echo 'to' "${REL}," 'you may want to remove your old installed kernel (unix)'
  143.     echo 'object and configuration files that have not been modified since'
  144.     echo 'installation (modified files will be saved), because their presence'
  145.     echo 'may prevent successful installation or configuration of a new kernel'
  146.     echo '\nDo not remove kernel files if you are upgrading from' "${REL}" 'or'
  147.     echo 'later.'
  148.     echo '\nDo you want to remove the unmodified kernel files? (yes/no) [no] \c'
  149.     read ans
  150.     case "$ans" {
  151.     y*|Y*)
  152.         echo '\nChecking for modified files; may take a few minutes. \c'
  153.         showfiles -smr $rbase -- /var/sysgen 2>/dev/null |\
  154.             sed s,var/sysgen/,, > /tmp/modvar$$
  155.         showfiles -smr $rbase -- /usr/cpu/sysgen 2>/dev/null |\
  156.             sed s,usr/cpu/sysgen/,, > /tmp/modusr$$
  157.         if [ -s /tmp/modvar$$ -o -s /tmp/modusr$$ ]; then
  158.         if [ -s /tmp/modvar$$ ]; then
  159.             echo \\nModified installed kernel files saved in /var/sysgen.O:
  160.             mkdir -p $rbase/var/sysgen.O
  161.             # errs will be on files "modified" because they are missing.
  162.             (cd $rbase/var/sysgen && cpio -dmp $rbase/var/sysgen.O \
  163.                 </tmp/modvar$$) >/dev/null 2>&1
  164.             (cd $rbase/var/sysgen.O && (l="`echo *`"; if [ "$l" != '*' ];
  165.                 then find * -type f -print; fi))
  166.  
  167.         fi
  168.         if [ -s /tmp/modusr$$ ]; then
  169.             echo \\nModified installed kernel files saved in /usr/cpu/sysgen.O:
  170.             mkdir -p $rbase/usr/cpu/sysgen.O
  171.             # errs will be on files "modified" because they are missing.
  172.             (cd $rbase/usr/cpu/sysgen && cpio -dmp $rbase/usr/cpu/sysgen.O \
  173.                 </tmp/modusr$$) >/dev/null 2>&1
  174.             (cd $rbase/usr/cpu/sysgen.O && (l="`echo *`"; if [ "$l" != '*' ];
  175.                 then find * -type f -print; fi))
  176.         fi
  177.         else echo . Note: no modified kernel files exist.
  178.         fi
  179.         rm -f /tmp/mod*$$
  180.         echo '\nRemoving kernel directories var/sysgen and usr/cpu/sysgen'
  181.         rm -rf $rbase/var/sysgen $rbase/usr/cpu/sysgen
  182.         ;;
  183.     }
  184. }
  185.  
  186.  
  187. oldunix()
  188. {
  189.     # this is mainly so we don't run out of space on the miniroot when we
  190.     # try to save the old kernel there, but it can help a lot with the install
  191.     # itself also.
  192.     rootfree=7168 # 7MB; more than enough for the largest kernel we know of
  193.  
  194.     set `df -k $rbase | sed -n '$p'`
  195.     if [ "$5" -lt $rootfree -s $rbase/unix ]
  196.     then
  197.         echo "\nYou have limited free space on your root filesystem ($5 KB)."
  198.         echo 'This may cause some problems in completing your installation.'
  199.         echo 'If you are installing kernel drivers, or the full OS, you'
  200.         echo 'may wish to remove your current /unix to create more space.'
  201.         echo '(This should not be done if you are installing new drivers or'
  202.         echo 'the full IRIX release.)  Do you wish to remove /unix? (yes/no) [no] \c'
  203.         read ans
  204.         case "$ans" {
  205.         y*|Y*) rm $rbase/unix && echo Removed old /unix ;;
  206.         }
  207.     fi
  208. }
  209.  
  210. # a function so the 'return' in the trap handler works right.
  211. endit()
  212. {
  213.     rm -f /tmp/*$$*; echo "$endmsg"; read answer
  214. }
  215.  
  216. # }
  217.  
  218. # main sequence starts here, using the functions above
  219.  
  220.  
  221. # Check done after xwsh opened if swmgr used, so it's visible.
  222. if [ "$instmode" = "client" -o "$instmode" = "prototype" ]
  223. then echo This script should only be run if you are not installing software
  224.     echo into an alternate location.  Nothing to do, since -r used.
  225.     endit
  226.     exit 0
  227. fi
  228.  
  229. # for paging, and interactive file removal list.  Does not deal with linewrap
  230. ttylines=`stty -a 2>/dev/null|grep rows|sed 's/.*\( [0-9][0-9]*\) rows.*/\1/'`
  231. if [ "$ttylines" -le 0 ]
  232.     then ttylines=24  # assume serial console
  233. elif [ "$ttylines" -le 10 ]
  234.     then ttylines=10 # need a reasonable amount of space...
  235. fi
  236. ttylines=`expr $ttylines - 1` # leave room for prompt at bottom
  237. rmlines=`expr $ttylines - 4` # context, and some linewrap
  238.  
  239.  
  240. # abort the current function, and continue with the next one,
  241. # if we get an interrupt
  242. trap 'echo \\n\\nInterrupted\\n; return' 2 3 15
  243.  
  244. echo '\nTo stop the current cleanup activity, press Control-C at any time.\n'
  245.  
  246. diskspace
  247.  
  248. oldkernel
  249.  
  250. oldunix
  251.  
  252. endit
  253.  
  254. exit 0
  255.